package com.sunspring.zdcall.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.sunspring.zdcall.common.constant.enums.DatasourceEnum;
import lombok.Data;

import java.sql.Driver;

/**
 * 数据来源
 * @author wulei
 * @date 2018-12-25
 **/
public class ZdConfigDatasource {

    /**
     * 数据来源Id
     */
    private Integer datasourceId;

    /**
     * 数据类型 1:db 2:json 3:xml
     */
    private Integer sourceType;

    /**
     * 数据源URL
     */
    private String sourceUrl;

    /**
     * 用户名
     */
    private String username;

    /**
     * 密码
     */
    private String password;

    /**
     * 数据库类型 1:sqlServer 2:mysql 3:oracle
     */
    private Integer dbType;

    /**
     * 数据库驱动
     */
    @JsonIgnore
    private String driverClassName;

    /**
     * 描述
     */
    private String description;

    public ZdConfigDatasource() {

    }

    public ZdConfigDatasource(Integer id,String sourceUrl, String username, String password,Integer dbType) {
        this.datasourceId = id;
        this.sourceUrl = sourceUrl;
        this.username = username;
        this.password = password;
        this.dbType = dbType;
        if (dbType == DatasourceEnum.sqlServer.getCode()) {
            setDriver("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        }
        else if (dbType == DatasourceEnum.mysql.getCode()) {
            /*setDriver("com.mysql.jdbc.Driver"); 弃用*/
            setDriver("com.mysql.cj.jdbc.Driver");
        }
    }

    public Integer getDatasourceId() {
        return datasourceId;
    }

    public void setDatasourceId(Integer datasourceId) {
        this.datasourceId = datasourceId;
    }

    public Integer getSourceType() {
        return sourceType;
    }

    public void setSourceType(Integer sourceType) {
        this.sourceType = sourceType;
    }

    public String getSourceUrl() {
        return sourceUrl;
    }

    public void setSourceUrl(String sourceUrl) {
        this.sourceUrl = sourceUrl;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getDbType() {
        return dbType;
    }

    public void setDbType(Integer dbType) {
        this.dbType = dbType;
    }

    public String getDriver() {
        return driverClassName;
    }

    public void setDriver(String driverClassName) {
        this.driverClassName = driverClassName;
    }

    @Override
    public String toString() {
        return "ZdConfigDatasource{" +
                "datasourceId=" + datasourceId +
                ", sourceType=" + sourceType +
                ", sourceUrl='" + sourceUrl + '\'' +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", dbType=" + dbType +
                ", driverClassName='" + driverClassName + '\'' +
                '}';
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
}
